from transformers import pipeline

class NewsAnalyzer:
    def __init__(self):
        self.sentiment_analyzer = pipeline("sentiment-analysis", 
                                         model="nlptown/bert-base-multilingual-uncased-sentiment")
        self.keyword_extractor = pipeline("ner", model="dslim/bert-base-NER")
    
    def analyze_news(self, text):
        """分析新闻情感和提取关键实体"""
        sentiment = self.sentiment_analyzer(text[:512])[0]
        entities = self.keyword_extractor(text[:512])
        return {
            'sentiment': sentiment,
            'entities': [e for e in entities if e['entity'] in ['ORG', 'PRODUCT']]
        } 